class CreateToxinAndReconciliationData < ActiveRecord::Migration
  def self.up
    toxin_1 = Toxin.find_or_create_by_name("domoic acid")
    toxin_1.save
    toxin_2 = Toxin.find_or_create_by_name("isodomoic acid C")
    toxin_2.save
    
    oct24_toxin_names = ['amphidinol', 'azaspiracid', 'brevetoxin', 'caribenolide I', 'ciguatoxin 3C', 'ciguatoxin 4A', 'ciguatoxin 4B', 
    'ciguatoxin-like toxin', 'cooliatoxin', 'dinophysistoxin-1', 'dinophysistoxin-2', 'fast acting toxin', 'hemolysin', 'isodomoic acid A', 
    'isodomoic acid B', 'karlotoxin', 'maitotoxin-like toxin', 'maitoxin', 'mascarenotoxin-A', 'mascarenotoxin-B', 'okadaic acid', 
    'ostreocin D', 'ostreotoxin-1', 'ostreotoxin-3', 'pectenotoxin-2', 'prorocentrolide B', 'yessotoxin']
    oct24_toxin_names.each do |toxin_name|
      toxin = Toxin.create!(:name=> toxin_name)
    end
    
    verbatim_phrase = "Produces domoic acid and isodomoic acid C."
    
    #Save the relation between the phrase and the toxins
    toxin_reconciliation_1 = ToxinReconciliation.new
    toxin_reconciliation_1.verbatim_phrase = verbatim_phrase
    toxin_reconciliation_1.toxin = toxin_1
    toxin_reconciliation_1.save
    
    toxin_reconciliation_2 = ToxinReconciliation.new
    toxin_reconciliation_2.verbatim_phrase = verbatim_phrase
    toxin_reconciliation_2.toxin = toxin_2
    toxin_reconciliation_2.save

    oct24_verbatim_to_toxin = {"A strain from Canada was found to produce domoic acid."=>"domoic acid", "A strain from Canada and one from New Zealand found to produce domoic acid."=>"domoic acid", 
    "A strain from New Zealand tested positive for domoic acid."=>"domoic acid", "Compounds with haemolytic and antifungal properties (amphidinols) known."=>"hemolysin", 
    "Compounds with haemolytic and antifungal properties (amphidinols) known."=>"amphidinol", "Culture material found to produce brevetoxin (ELISA)"=>"brevetoxin", 
    "Domoic acid producer"=>"domoic acid", "Found to produce brevetoxin in culture."=>"brevetoxin", "Found to produce brevetoxin in culture"=>"brevetoxin", 
    "Found to produce okadaic acid"=>"okadaic acid", "Haemolysins have been isolated"=>"hemolysin", "Material from Belize produces okadaic acid"=>"okadaic acid", 
    "fast acting toxin"=>"fast acting toxin", "hemolysin"=>"hemolysin", "haemolytic toxins"=>"hemolysin", " maitoxin"=>"maitoxin", "azaspiracid"=>"azaspiracid", 
    "ciguatoxins 4A, 4B and 3C"=>"ciguatoxin 4A", "ciguatoxins 4A, 4B and 3C"=>"ciguatoxin 4B", "ciguatoxins 4A, 4B and 3C"=>"ciguatoxin 3C", 
    "ciguatoxin- and maitotoxin-like toxins."=>"ciguatoxin-like toxin", "ciguatoxin- and maitotoxin-like toxins."=>"maitotoxin-like toxin", "dinophysistoxin-1"=>"dinophysistoxin-1", 
    " okadaic acid"=>"okadaic acid", " DTX-1 "=>"dinophysistoxin-1", " dinophysistoxin-2 "=>"dinophysistoxin-2", "(DTX2)"=>"dinophysistoxin-2", 
    "(DTX1)"=>"dinophysistoxin-1", " pectenotoxin-2 "=>"pectenotoxin-2", "(PTX2)"=>"pectenotoxin-2", " PTX-2."=>"pectenotoxin-2", " ostreocin D,"=>"ostreocin D", 
    "ostreotoxin-1 and -3"=>"ostreotoxin-1", "ostreotoxin-1 and -3"=>"ostreotoxin-3", " yessotoxin,"=>"yessotoxin", " cooliatoxin "=>"cooliatoxin", 
    "(caribenolide I)"=>"caribenolide I", "isodomoic acid A and B."=>"isodomoic acid A", "isodomoic acid A and B."=>"isodomoic acid B", "haemolytic compounds"=>"hemolysin", 
    " DTX1,"=>"dinophysistoxin-1", "Prorocentrolide B,"=>"prorocentrolide B", " okadaic acid,"=>"okadaic acid", "mascarenotoxin-A and -B "=>"mascarenotoxin-A", 
    "mascarenotoxin-A and -B "=>"mascarenotoxin-B", " DTX-2 "=>"dinophysistoxin-2", " domoic acid"=>"domoic acid", " brevetoxins,"=>"brevetoxin", 
    " karlotoxins "=>"karlotoxin"}
    oct24_verbatim_to_toxin.each_pair do |verbatim_phrase, toxin_name|
      toxin = Toxin.find_by_name(toxin_name)
      toxin_reconciliation = ToxinReconciliation.create!(:verbatim_phrase=>verbatim_phrase, :toxin=>toxin)
    end
    
    
  end

  def self.down
    Toxin.destroy_all
    ToxinReconciliation.destroy_all
  end
end
